package uk.ac.ebi.microarray.expressionprofiler.ra.fs.impl;

import java.io.Serializable;

import javax.naming.NamingException;
import javax.naming.Reference;
import javax.resource.Referenceable;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ManagedConnectionFactory;

import uk.ac.ebi.microarray.expressionprofiler.ra.fs.FileSystemConnection;
import uk.ac.ebi.microarray.expressionprofiler.ra.fs.FileSystemConnectionFactory;
import uk.ac.ebi.microarray.expressionprofiler.ra.fs.FileSystemConnectionInfo;

public class FileSystemConnectionFactoryImpl implements FileSystemConnectionFactory, Serializable, Referenceable {

    private static final long serialVersionUID = 4663222207447959599L;
    
    private ManagedConnectionFactory mcf;
    private ConnectionManager cm;
    private Reference reference;

    public FileSystemConnectionFactoryImpl(ManagedConnectionFactory factory, ConnectionManager cm) {
        this.mcf = factory;
        this.cm = cm;
    }

    public FileSystemConnection getConnection(FileSystemConnectionInfo info) throws ResourceException {
        return (FileSystemConnection) cm.allocateConnection(mcf, info);
    }

    public void setReference(Reference reference) {
        this.reference = reference;
    }

    public Reference getReference() throws NamingException {
        return reference;
    }
}
